home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!astrac1.demon.co.uk
- From: root <root@astrac1.demon.co.uk>
- Newsgroups: comp.lang.rexx
- Subject: Re: Newbie: numerics in REXX
- Date: Wed, 10 Jan 1996 12:12:12 GMT
- Organization: ASTRAC Ltd: IBM PC/mainframe EIS/MIS consultancy
- Message-ID: <1996Jan10.121212.269@astrac1.demon.co.uk>
- References: <DKBLIu.22B@rockyd.rockefeller.edu>
- X-NNTP-Posting-Host: astrac1.demon.co.uk
- X-Newsreader: TIN [version 1.2 PL2]
- X-Mail2News-Path: relay-4.mail.demon.net!post.demon.co.uk!astrac1.demon.co.uk
-
- Dan Samber (dan@pendragon.rockefeller.edu) wrote:
- : OK. I'm having trouble adjusting to the fact that REXX has no variable
- : types.... But in any case.... what I need to know is if there is a function
- : that will convert a string like 123 to actually be 123. As far as I can
- : tell saying
-
- : data = 123
-
- : is equivalent to
-
- : data = "123"
-
- : I know this since running
-
- : data = 1
- : say data
- : outputs : 1
-
- : produces different results then running
-
- : data = "1"x /* this is hex 1 same as decimal 1 or binary 1 */
- : say data
- : outputs a funcky character (it seems like its trying to print ASCII 1 which
- : is something funcky).
-
- : I have tried all the c2d d2h etc.... and am losing my mind.
-
- : Do I need to write a function that parses each character and subtracts
- : off the ASCII offset and multiply by 10^placeholder etc. or something
- : ugly like this????
-
-
-
- : HELP ME!
-
- : Thanks!
-
-
- : Dan
-
- Dan,
-
- When I first started with REXX a few years ago, I had a massive
- battle with the c2{x,d} and {x,d}2c functions, and the way they
- relate to the difference between what is actually stored in the
- variables and what is printed on the screen.
-
- Let's take d2c. 'c=d2c(45); say c' - after this, the variable c
- would contain the BINARY value 45 (presumably in one byte of
- storage), and 'say c' would cause whatever the character no.
- (decimal) 45 was in the table of printable characters (ASCII or
- EBCDIC) used on your system. (In ASCII, it's the hyphen.) On the
- other hand, 'd=45; say d' - on the screen are printed the ASCII
- representations of '4' and '5', and the variable d would be a
- string of bytes containing the ASCII values producing those two
- digits ('4' is 52 and '5' is 53.)
-
- x2c works exactly the same, except that it uses hex strings
- rather than decimal numbers. For example 'c=x2c("2A"); say c': c
- contains the binary value 2A, and 'say c' would produce character
- no. 2A on the screen (in ASCII, according to my table, it would
- be "*".) On the other hand, after 'x=2A; say x', what would
- appear on the screen would be the characters representing 2 and A
- (ASCII (decimal) 50 and 65), and the actual value of x would be a
- string of bytes containing the values 50 and 65.)
-
- c2{d,x} work the other way: "c='2A'x; x=c2x(c); say x" - c has
- the binary value 2A; x is the string of bytes containing 50 and
- 65; on the screen are printed ASCII characters 50 and 65 - "2"
- and "A".
-
- Does this make sense? I know what you mean about the feeling of
- going insane over this one - I've been there! I hope I've helped
- to clarify rather than re-muddy the waters: if the latter, or if
- I've screwed up any of the examples, then get back to me.
- These functions are enormously powerful and flexible when they're
- fully grasped.
-
- Regards,
- Peter
-
-
-
-
-